package com.jvxb.manage.livable.controller;

import com.jvxb.common.web.RespMsg;
import com.jvxb.manage.livable.service.DbDeployService;
import com.jvxb.manage.livable.vo.ClusterApplyVo;
import com.jvxb.manage.livable.vo.WorkOrderOperateVo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author jvxb
 * @since 2022-01-07
 */
@RestController
@RequestMapping("/db/deploy")
public class DbDeployController {


    @Autowired
    DbDeployService dbDeployService;

    /**
     * 部署工单申请
     * @param clusterApplyVo
     * @return
     */
    @PostMapping("/apply")
    public RespMsg apply(@RequestBody ClusterApplyVo clusterApplyVo) {
        try {
            dbDeployService.checkBeforeApply(clusterApplyVo);
            dbDeployService.apply(clusterApplyVo);
            return RespMsg.ok();
        } catch (Exception e) {
            return RespMsg.error(e.getMessage());
        }
    }

    /**
     * 部署工单详情
     * @return
     */
    @GetMapping("/getDeployInfoByWorkOrderId")
    public RespMsg getDeployInfoByWorkOrderId(String dbType, Long workOrderId) {
        Map deployInfo = dbDeployService.getDeployInfoByWorkOrderId(dbType, workOrderId);
        return RespMsg.ok(deployInfo);
    }

    /**
     * 部署工单执行
     * @param operateVo
     * @return
     */
    @PostMapping("/executeOrder")
    public RespMsg executeOrder(@RequestBody WorkOrderOperateVo operateVo) {
        dbDeployService.executeOrder(operateVo);
        return RespMsg.ok();
    }

}
